import {
	defineStore
} from 'pinia';

export const useCustomStore = defineStore('user', {
	state: () => ({
		realName: '',
		avatar: '',
	}),
	actions: {
		setUserInfo() {
			this.realName = uni.getStorageSync('realName') || '';
			this.avatar = uni.getStorageSync('avatar') || '';
		},
		// 个人信息方法
		ownInfo() {
			uni.navigateTo({
				url: '/pages/UserInfo/UserInfo',
			});
		},
		// 上传记录方法
		getUploadHistory() {
			uni.showModal({
				title: '提示',
				content: '功能待开发',
				success: function(res) {

				}
			});
		},
		// 联系客服方法
		contact() {
			uni.showModal({
				title: '提示',
				content: '功能待开发',
				success: function(res) {
					// if (res.confirm) {
					//   uni.makePhoneCall({
					//     phoneNumber: '123456',
					//   });
					// } else if (res.cancel) {
					//   return;
					// }
				},
			});
		},
		// 退出登录方法
		loginOut() {
			try {
				uni.removeStorageSync('Authorization');
				uni.showToast({
					title: '退出成功',
					icon: 'success',
					position: 500,
				});
				uni.redirectTo({
					url: '/pages/Login/Login',
				});
			} catch (e) {
				// TODO handle the exception
			}
		},
	},
});